<?php 
	include("../includes/connect_db.php"); 
	$idresto = (isset($_POST["idresto"])) ? $_POST["idresto"] : "" ;

	$i = 1;
	$sql_resto_menu = "SELECT * FROM resto_menu WHERE idresto = '$idresto'";
	$query_resto_menu = mysql_query($sql_resto_menu);
	if (mysql_num_rows($query_resto_menu) > 0) {
		$query_resto_menu = mysql_query($sql_resto_menu);
		while ($result_resto_menu = mysql_fetch_array($query_resto_menu)) {
			$sql_menu = "SELECT * FROM menu WHERE id = '$result_resto_menu[idmenu]'";
			$query_menu = mysql_query($sql_menu);
			$result_menu = mysql_fetch_array($query_menu);
?>
		<tr>
			<td class="no">
				<?php echo $i; ?>
			</td>
			<td class="input-table-placer">
				<input type="text" class="input-table input-menu" value="<?php echo $result_menu[nama]; ?>">
				<input type="hidden" class="idmenu" value="<?php echo $result_menu[id]; ?>">
			</td>
			<td></td>
			<td class="input-table-placer">
				<input type="number" class="input-table input-jumlah" value="<?php echo $result_resto_menu[jumlah] ?>">
			</td>
			<td><a href="#" class="remove-line"><i class="fa fa-times"></i></a></td>
		</tr>
<?php
			$i++;
		}
	}

	$sql_delete_resto_menu = "DELETE FROM resto_menu WHERE idresto = '$idresto'";
	$query_delete_resto_menu = mysql_query($sql_delete_resto_menu);
?>

<SCRIPT TYPE="text/javascript">
	$(document).ready(function() {
		$('.input-menu').typeahead({
      source: function(typeahead, query) {
        $.ajax({
          url: "/action/act_resto.php",
          dataType: "json",
          type: "POST",
          data: {
          	key: query,
          	act: 1
          },
          success: function(data) {
            var return_list = [], i = data.length;
            while (i--) {
              return_list[i] = {id: data[i].id, value: data[i].kode + " | " + data[i].nama, nama: data[i].nama};
            }
            typeahead.process(return_list);
          }
        });
      },
      onselect: function(obj) {
        this.$element.val(obj.nama);
        this.$element.closest('td').find('.idmenu').val(obj.id);
      }
		});
	});
</SCRIPT>
